package firm;

import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;


public class Worker extends Thread {
	//private Koordynator koordynator;
	private Product newProduct;
	private int ID;
 	private AtomicInteger current_Tasks;

	Random generator = new Random();
	GlobalData global;
	private Task[] taskArray;
	private Product[] product_array;
	private Product[] temp_product_Array;
	private Addition_Machine[] addingMachines;
	private Plurar_Machine[] pluringMachines;
	private AtomicInteger busy = new AtomicInteger(0) ;
	private boolean having_a_task = false;
	
	public void taking_a_task(boolean value){
		having_a_task = true;
	}
	public void free(int Id){
		having_a_task = false;
	}
	public boolean is_having_a_task(int Id){
		return having_a_task;
	}
	
	public Worker(int ID, Task[] taskArray, Product[] product_array, Product[] temp_product_Array, Addition_Machine[] addingMachines, Plurar_Machine[] pluringMachines) 
	{
		//this.koordynator = t;
		this.ID = ID;
		this.taskArray = taskArray;
		this.product_array = product_array;
		this.temp_product_Array = temp_product_Array;
		this.addingMachines = addingMachines;
		this.pluringMachines = pluringMachines;
	}

	
	public void run() 
	{
		//synchronized(busy){
			while(true){
				GlobalData.cTalking.wez(this.ID, newProduct, taskArray, product_array, temp_product_Array, addingMachines, pluringMachines);

				try {
					sleep((int)(GlobalData.WORKER_SLEEP));
				} 
				catch (InterruptedException e) {  }

			}	
		//}
	}
}
